package handler

import (
	"context"
	"github.com/go-errors/errors"
	"go.uber.org/zap"
	"takeout_server/basic/dao"
	__ "takeout_server/basic/proto/user"
)

type UserServer struct {
	__.UnimplementedUserServerServer
}

func (s *UserServer) UserRegister(_ context.Context, req *__.UserReq) (*__.UserResp, error) {
	where, err := dao.UserWhere(req.Name)
	if err != nil {
		zap.L().Info("用户查询失败")

	}
	if where.Id == 0 {
		register, err := dao.UserRegister(req.Name, req.Password, req.Phone)
		if err != nil {
			zap.L().Info("用户注册失败")
			return nil, errors.New("用户注册失败")
		}
		where = register

	}
	return &__.UserResp{UserId: int32(where.Id)}, nil
}
